<%@ page contentType="text/html;charset=UTF-8" %>﻿
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<meta content="" name="description"/>
<meta content="" name="author"/>
<script type="text/javascript" src="${ctx}/static/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="${ctx}/static/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/static/js/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" type="text/css" href="${ctx}/static/js/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/static/js/themes/IconExtension.css" />
<script type="text/javascript">
function myformatter(date){
    var y = date.getFullYear();  
    var m = date.getMonth()+1;  
    var d = date.getDate();  
    return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);  
}  
          
function myparser(s){
    if (!s) return new Date();  
    var ss = (s.split('-'));  
    var y = parseInt(ss[0],10);  
    var m = parseInt(ss[1],10);  
    var d = parseInt(ss[2],10);  
    if (!isNaN(y) && !isNaN(m) && !isNaN(d)){  
        return new Date(y,m-1,d);  
    } else {  
        return new Date();  
    }  
}
$(function(){
	 $("#startDate_begin").datebox("setValue","");  
	$("#startDate_end").datebox("setValue","");  
	$("#endDate_begin").datebox("setValue","");  
	$("#endDate_end").datebox("setValue",""); 
});

	var datagrid;//定义datagrid变量
	function searchWorkBill() {
		var ctx_val = $("#context_val").val();//获取上下文
		//获取维修单号，工单号，派工单号，开始时间，完成时间
		var billNo = $("#billNo").val();
		var workBillId = $('#workBillId').val();
		var deployBillId = $('#deployBillId').val();
		
		var billStt = $('#billStt').combobox('getValue');
		var emergentType = $('#emergentType').combobox('getValue');
		
		var empName = $('#empName').val();
		var startDate_begin = $('#startDate_begin').datebox('getValue');
		var startDate_end= $('#startDate_end').datebox('getValue');
		
		var endDate_begin  = $('#endDate_begin').datebox('getValue');
		var endDate_end  = $('#endDate_end').datebox('getValue');
		 datagrid=$('#data').datagrid({
			title : '维修单查询列表',
			iconCls : 'icon-edit',//图标  
			width : 700,
			height : 'auto',
			nowrap : false,
			striped : true,
			border : true,
			collapsible : false,//是否可折叠的  
			fit : true,//自动大小  
			url:ctx_val+"/ri/selRepairByCondition",
			method:"post",
			 queryParams: { 
				 'billNo': billNo ,
				 'workBillId':workBillId,
				 'deployBillId':deployBillId,
				 'billStt':billStt,
				 'emergentType':emergentType,
				 'empName':empName,
				 'startDate_begin':startDate_begin,
				 'startDate_end':startDate_end,
				 'endDate_begin':endDate_begin,
				 'endDate_end':endDate_end,
			 },
			remoteSort : false,
			idField : 'fldId',
			singleSelect:true,
			pagination : true,//分页控件  
			rownumbers : true,//行号  
			frozenColumns : [ [
			 {field:'id',title:'id',width:50,hidden:true},   
			 {field:'billNo',title:'工单号',width:100},   
			 {field:'workBillNo',title:'工单号',width:100,hidden:true,align:'center'},   
			 {field:'deployBillId',title:'派工单号',width:100,hidden:true},
			 {field:'billStt',title:'维修单状态',width:100,align:'center',
					 formatter:function(value){        
					 if(value==0){
						 return '待接收';        
					 } else if(value==1){
						 return '师傅已确认';        
					 }else if(value==2){
							return '延迟';        
					 }else if(value==3){
							return '完成';        
					 } else if(value==9){
							return '作废';        
					 }             
					 
			 }    
			 },
			 {field:'emergentType',title:'紧急程度',width:100,align:'center',
			 //状态，0待分派，1待处理，2（师傅回单后）待回访，3已完成，4退单（选择师傅退单？进入待处理状态），9作废
				 formatter:function(value){
						 if(value==0){
						 	return '不紧急';      
						 }else if(value==1){
						 	return '一般';        
						 }else if(value==2){
							 return '紧急';        
						 }                     
				
				 }  
			 },
			 {field:'empName',title:'用户姓名',width:150,align:'center',},
			 
			 {field:'startDate',title:'开始时间',width:180,align:'center',
				 formatter:function(value,row,index){
					 if(null!=value){
						 var unixTimestamp = new Date(value);
			             return unixTimestamp.toLocaleString();
					 }
	             }},
			 {field:'finishDate',title:'结束时间',width:180,align:'center',
				 formatter:function(value,row,index){
					 if(null!=value){
						 var unixTimestamp = new Date(value);
			             return unixTimestamp.toLocaleString();
					 }
			            
		          }
			 },
			] ],
			onRowContextMenu: function(e, rowIndex, rowData) {
				 //右键时触发事件
				 //三个参数：e里面的内容很多，真心不明白，rowIndex就是当前点击时所在行的索引，rowData当前行的数据
				 e.preventDefault(); //阻止浏览器捕获右键事件
				 $(this).datagrid("clearSelections"); //取消所有选中项
				 $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
				 $('#menu').menu('show', {
				 //显示右键菜单
				 left: e.pageX,//在鼠标点击处显示菜单
				 top: e.pageY
				 });
				 },
			toolbar : [ {
				text : '添加',
				iconCls : 'icon-add',
				handler : function() {
					var ctx_val = $("#context_val").val();
					$("#submitForm").attr("action", ctx_val+"/workBill/new" );
					$("#submitForm").attr("method", "get" );
					$("#submitForm").submit();
				}

			}, '-', {
				text : '修改',
				iconCls : 'icon-edit',
				handler : function() {
					var rows = datagrid.datagrid('getSelections');
					if(typeof(rows[0]) == "undefined"){
						window.alert("请选择一条要修改的数据");
						return false;
					}
					var id = rows[0].id;
					$("#id").val(id);
					
					var ctx_val = $("#context_val").val();
					$("#submitForm").attr("method", "post" );
					
					$("#submitForm").attr("action",
							ctx_val + "/workBill/viewBillById?id=" + id);
					$("#submitForm").submit();
				}

			},  ],

		});

		//设置分页控件  

		var p = $('#data').datagrid('getPager');

		$(p).pagination({
			pageSize : 10,//每页显示的记录条数，默认为10  
			pageList : [ 5, 10, 15 ],//可以设置每页记录条数的列表  
			beforePageText : '第',//页数文本框前显示的汉字  
			afterPageText : '页    共 {pages} 页',
			displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录',
		});
		

		 
		 
		 



	}


</script>
</head>
<body class="easyui-layout layout" style="background: #fff;"> 
<input type="hidden" value="${ctx}" id="context_val">
	<div id="imgShow"  style="position: absolute;display:none;border: 4px #ccc solid ;z-index:10;background-color:#fff;padding:5px;"><img src="" width="150px"></div>
	<div  region="north" border="false" title="维修单查询" collapsed="false"
		style="height: 130px; overflow:hidden;background: #eee;border-bottom:1px solid #ddd" align="left">
		<form id="searchForm">
			<table style="height: 100%;width:auto;">
				<tr>
					<td>维修单号：</td>
					<td><input class="easyui-textbox" type="text"
						name="billNo" id="billNo"></input></td>
					<td>工单号：</td>
					<td><input class="easyui-textbox" type="text"
						name="workBillId" id="workBillId"></input></td>
						
						<td>派工单号：</td>
					<td><input class="easyui-textbox" type="text"
						name="deployBillId" id="deployBillId"></input></td>
						<td>被分派人：</td>
					<td><input class="easyui-textbox" type="text"
						name="empName" id="empName"></input></td>
				</tr>
				<tr>
					<td>维修单状态：</td>
					<td><select class="easyui-combobox" editable=false
						name="billStt" id="billStt">
							<option value="">--请选择--</option>
							<option value="0">待接收</option>
							<option value="1">维修人员已接收</option>
							<option value="2">延迟</option>
							<option value="3">完成</option>
							<option value="9">作废</option>
					</select></td>
					<td>紧急度:</td>
					<td><select value=1 class="easyui-combobox" editable=false
						name="emergentType" id="emergentType">
							<option value="">--请选择--</option>
							<option value="0">不紧急</option>
							<option value="1">一般</option>
							<option value="2">紧急</option>
					</select></td>
					<td>开始时间</td>
					<td><input name="startDate_begin" id="startDate_begin" class="easyui-datebox" >-<input name="startDate_end" id="startDate_end" class="easyui-datebox" > </td>
					
					<td align="right" >完成时间</td>
					<td><input name="endDate_begin" id="endDate_begin" class="easyui-datebox" >-<input  name="endDate_end" id="endDate_end"class="easyui-datebox" > </td>	
					<td></td><td></td>
				</tr>
				<tr>
					<td colSpan="8" align="center">
						<a href="javascript:void(0);"
						class="easyui-linkbutton" iconCls="icon-search"
						onclick="searchWorkBill();">查询</a>
					</td>
				</tr>
			</table>
		</form>
		
	</div>
	<div region="center" border="false">
		<table id="data">  
			<tr>
				<td><span>输入查询条件进行维修单查询。</span></td>
			</tr>
		</table>
	</div>


</body>
</html>